// 返回新对象
function keyDeal(obj){
    if(typeof obj != "object"){
        return obj;
    }else if(obj instanceof Array){
        for(let i in obj){
            obj[i] = keyDeal(obj[i])
        }
        return obj;
    }

    let result = {};
    for(let key in obj){
        let str = textChange(key);
        if(typeof obj[key] == 'object'){
            result[str] = keyDeal(obj[key]);
        }else{
            result[str] = obj[key]
        }
    }
    return result;
}

// 处理字母
function textChange(string){
    return string.split("").reduce((res,str,i)=>{
        if( /[A-Z]/.test(str) ){
            str = str.toLowerCase();
            i != 0 && (str = "_" + str);
        }
        return res += str;
    },"")
}

module.exports = keyDeal;